package snippets.cse524.activeDates.evaluation;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class LifespanParser {
	public static final void main(String[] args) throws FileNotFoundException {

		Scanner in = new Scanner(new File(args[0]));

		while (in.hasNextLine()) {
			String[] parts = StringUtils.split(in.nextLine().trim(), '\t');

			if (parts.length == 0)
				continue;

			String name = parts[0];

			Pattern year = Pattern.compile("([0-9]{4})");
			Matcher yearMatcher = year.matcher(parts[1]);

			int minYear = Integer.MAX_VALUE;
			int maxYear = Integer.MIN_VALUE;

			while (yearMatcher.find()) {
				int thisYear = Integer.parseInt(yearMatcher.group());

				if (thisYear < minYear)
					minYear = thisYear;
				if (thisYear > maxYear)
					maxYear = thisYear;
			}

			if (minYear == Integer.MAX_VALUE)
				minYear = -1;
			if (maxYear == Integer.MIN_VALUE)
				maxYear = -1;

			System.out.println(StringUtils.join(
					new String[] { name, Integer.toString(minYear),
							Integer.toString(maxYear) }, "\t"));
		}

	}
}
